{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "def calculate_gpt_price(model_type, input_tokens, output_tokens):\n",
    "    # Prices per million tokens\n",
    "    prices = {\n",
    "        'gpt-4o-mini': {'input': 0.150, 'output': 0.600},\n",
    "        'gpt-3.5-turbo': {'input': 0.500, 'output': 1.500},\n",
    "        'gpt-4-turbo': {'input': 10.00, 'output': 30.00}\n",
    "    }\n",
    "    \n",
    "    # Calculate cost based on the model type and number of tokens\n",
    "    if model_type in prices:\n",
    "        input_cost = (input_tokens / 1_000_000) * prices[model_type]['input']\n",
    "        output_cost = (output_tokens / 1_000_000) * prices[model_type]['output']\n",
    "        total_cost = input_cost + output_cost\n",
    "        total_tokens = input_tokens + output_tokens\n",
    "        return total_cost,total_tokens\n",
    "    else:\n",
    "        return \"Invalid model type\"\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "331165 $0.19\n"
     ]
    }
   ],
   "source": [
    "\n",
    "price, token = calculate_gpt_price('gpt-3.5-turbo', 306_482, 24_683)  \n",
    "print(f\"{token} ${price:.2f}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "7105301 $1.36\n"
     ]
    }
   ],
   "source": [
    "price, token = calculate_gpt_price('gpt-4o-mini', 6_460_508, 644_793)  \n",
    "print(f\"{token} ${price:.2f}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4175265 $49.10\n"
     ]
    }
   ],
   "source": [
    "price, token = calculate_gpt_price('gpt-4-turbo', 3_808_122, 367_143)\n",
    "print(f\"{token} ${price:.2f}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "import openai\n",
    "\n",
    "GPT_MODEL = \"gpt-3.5-turbo\"\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "response = openai.ChatCompletion.create(\n",
    "    model=GPT_MODEL,\n",
    "    messages=[\n",
    "        {\"role\": \"system\", \"content\": \"You are a helpful assistant.\"},\n",
    "        {\"role\": \"user\", \"content\": \"What is the capital of California?\"},\n",
    "        {\"role\": \"assistant\", \"content\": \"The capital of California is Sacramento.\"}\n",
    "    ]\n",
    "    )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<OpenAIObject chat.completion id=chatcmpl-A1OSpdGbn7pa0vAwUb9kFchbTCasi at 0x103de69e0> JSON: {\n",
       "  \"id\": \"chatcmpl-A1OSpdGbn7pa0vAwUb9kFchbTCasi\",\n",
       "  \"object\": \"chat.completion\",\n",
       "  \"created\": 1724895731,\n",
       "  \"model\": \"gpt-3.5-turbo-0125\",\n",
       "  \"choices\": [\n",
       "    {\n",
       "      \"index\": 0,\n",
       "      \"message\": {\n",
       "        \"role\": \"assistant\",\n",
       "        \"content\": \"The capital of California is Sacramento.\",\n",
       "        \"refusal\": null\n",
       "      },\n",
       "      \"logprobs\": null,\n",
       "      \"finish_reason\": \"stop\"\n",
       "    }\n",
       "  ],\n",
       "  \"usage\": {\n",
       "    \"prompt_tokens\": 35,\n",
       "    \"completion_tokens\": 7,\n",
       "    \"total_tokens\": 42\n",
       "  },\n",
       "  \"system_fingerprint\": null\n",
       "}"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "response"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "# , 'lotextusavufubynyb', 'wuxesafetatextysima pebutextiwafufok', 'tuchonip', ' S', 'xyvovikofutex pylekazuquekedajota E', 'wik xofoxujegerigubo ?', 'gipimakude 1', ' O', ' ^', 'lakiquuvuhenugu vajyquy P', ' 6', 'fezore', 'vabithin textusichytilejocoke', ' B', 'lasuthasebuvy que &', 'mymanuzuzudyc thazufys y', '', ' ?', 'gecohywelawu', 'wath'\n",
    "\n",
    "\n",
    "def sat(y: List[bool], x=['ryxadec', 'pyfixotibujadyxe', 'mopubywewexi witethig 7', ' !', 'jethi sed c']):\n",
    "    assert len(x) == len(y)\n",
    "    for s, b in zip(x, y):\n",
    "        if len(s.split(\" \")[-1]) == 1:\n",
    "            assert b == s[-1].isalpha()\n",
    "        else:\n",
    "            assert not b\n",
    "    return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "ryxadec False\n",
      "pyfixotibujadyxe False\n",
      "mopubywewexi witethig 7 False\n",
      " ! False\n",
      "jethi sed c True\n"
     ]
    }
   ],
   "source": [
    "x = ['ryxadec', 'pyfixotibujadyxe', 'mopubywewexi witethig 7', ' !', 'jethi sed c']\n",
    "y = [False, False, False, False, True]\n",
    "for s, b in zip(x, y):\n",
    "    print(s, b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "ryxadec\n",
      "pyfixotibujadyxe\n",
      "7\n",
      "!\n",
      "c\n"
     ]
    }
   ],
   "source": [
    "for string in x:\n",
    "    print(string.split(\" \")[-1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
